package com.lxl.hadoop.nline;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.Iterator;

/**
 * @Author lixilin
 * @Date 2021/12/25 9:53
 * @Description
 */
public class NLineReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
    IntWritable v = new IntWritable();

    protected void reduce(Text key, Iterable<IntWritable> values, Context context
    ) throws IOException, InterruptedException {
        int sum =0;
        Iterator<IntWritable> iterator = values.iterator();
        while (iterator.hasNext()) {
            sum+=iterator.next().get();
        }
        v.set(sum);
        context.write(key,v);
    }
}
